package hyl.base.mq.active;

import java.util.Properties;

import hyl.base.mq.IConfig;
import hyl.core.MyFun;
import hyl.core.conf.MyPrp;

public class ActConfig implements IConfig {

	// ActiveMq 的默认用户名
	private String USERNAME = "admin";
	// ActiveMq 的默认登录密码
	private String PASSWORD = "activemq";
	// ActiveMQ 的链接地址
	private String BROKEN_URL = "tcp://192.168.0.144:61616";
	// ActiveMQConnection.DEFAULT_BROKER_URL;
	private String TIMEOUT = "300";
	//private Boolean isLoad = false;
	private static final String LOADPATH = "mq/activemq.conf";
	private static ActConfig defaultConfig = null;
	
	public static ActConfig loadFile(String filename) {
		if (MyFun.isEmpty(filename)) {
			if (defaultConfig == null)
				defaultConfig = new ActConfig(LOADPATH);
			return defaultConfig;
		} else
			return new ActConfig(filename);
	}

	MyPrp _pp;



	public Properties getProperties() {
		return _pp.getAll();
	}

	public boolean isValid() {
		return !_pp.isEmpty();
	}

	public ActConfig(String filename) {
		_pp = new MyPrp(filename);
		if (_pp.isEmpty()) {
			System.out.println("缺少配置文件：" + filename);
		} else {
			setUser(_pp.get("user"));
			setPassword(_pp.get("pass"));
			setUrl(_pp.get("url"));
			setTimeOut(_pp.get("timeout"));
		}
	}

	public void setTimeOut(String timeout) {
		if (!MyFun.isEmpty(timeout))
			TIMEOUT = timeout;
	}

	public String getTimeOut() {
		return TIMEOUT;
	}

	/**
	 * @param uSERNAME the uSERNAME to set
	 */
	public void setUser(String uSERNAME) {
		if (!MyFun.isEmpty(uSERNAME))
			USERNAME = uSERNAME;
	}

	/**
	 * @param pASSWORD the pASSWORD to set
	 */
	public void setPassword(String pASSWORD) {
		if (!MyFun.isEmpty(pASSWORD))
			PASSWORD = pASSWORD;
	}

	/**
	 * @param bROKEN_URL the bROKEN_URL to set
	 */
	public void setUrl(String bROKEN_URL) {
		if (!MyFun.isEmpty(bROKEN_URL))
			BROKEN_URL = bROKEN_URL;
	}

	@Override
	public String getUrl() {
		// TODO Auto-generated method stub
		return BROKEN_URL;
	}

	@Override
	public String getPassword() {
		// TODO Auto-generated method stub
		return PASSWORD;
	}

	@Override
	public String getUser() {
		// TODO Auto-generated method stub
		return USERNAME;

	}

}
